home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 6 / QRZ Ham Radio Callsign Database - Volume 6.iso / pc / files / amiga / akit29m.lha / AmigaNOS / TCPIP / GenDOM.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-24  |  1.4 KB  |  60 lines

  1. /* Here is a program to convert your hosts.net to domain.txt */
  2. #include <stdio.h>
  3. #include <ctype.h>
  4. #include <string.h>
  5.  
  6. #define LINELEN 256
  7. /* copyright 1989 - John D. Hays, KD7UW */
  8. /*           1991 - John Heaton,  G1YYH */
  9. main(int argc,char *argv[])
  10. {
  11.  
  12.     FILE *fi,*fo;
  13.     char string[LINELEN-1];
  14.     char addr[20],hname1[80],hname2[80];
  15.     char *x,*y,*z;
  16.  
  17.     fprintf(stderr,"COPYRIGHT 1989/91 - KD7UW/G1YYH\n");
  18.     if (argc <= 2) {
  19.         fprintf(stderr,"Usage: %s <Hosts.NET> <Domain.TXT> <FULL>\n\007",argv[0]);
  20.         exit(0);
  21.     }
  22.  
  23.     if ((fi=fopen(argv[1],"r")) != NULL) {
  24.         fo = fopen(argv[2],"w");
  25.         while (fgets(string,LINELEN,fi) != NULL) {
  26.             y = strchr(string,'\n');
  27.             *y = '\0';
  28.             addr[0] = '\0';
  29.             hname1[0] = '\0';
  30.             hname2[0] = '\0';
  31.             if ((string[0] == '#') || (strlen(string) < 3)) {
  32.                 fprintf(fo,"%s\n",string);
  33.             } else {
  34.                 y = strchr(string,'#');
  35.                 if (y != NULL) {
  36.                     if (argv[3] != NULL)
  37.                         fprintf(fo,"#%s\n",y);
  38.                     *y = '\0';
  39.                 }
  40.                 sscanf(string,"%s%s%s",addr,hname1,hname2);
  41.                 fprintf(stderr,"%16s\r",addr);
  42.                 if (strchr(hname1,'.'))    {
  43.                     x = hname1;
  44.                     z = hname2;
  45.                 } else {
  46.                     x = hname2;
  47.                     z = hname1;
  48.                 }
  49.                 if ((*x == '\0') || (*z == '\0')) {
  50.                     fprintf(fo,"%s\tIN\tA\t%s\n",hname1,addr);
  51.                 } else {
  52.                     if (argv[3] != NULL)
  53.                         fprintf(fo,"%s\tIN CNAME\t%s\n",z,x);
  54.                     fprintf(fo,"%s\tIN A\t%s\n",x,addr);
  55.                 }
  56.             }
  57.         }
  58.     }
  59. }
  60.